package catgory;

import org.apache.commons.collections4.SetUtils;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.assertj.core.util.Lists;
import org.assertj.core.util.Sets;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * describe:
 *
 * @author huxingjie
 * @date 2019/04/22
 * @since 3.6
 */
public class FileList {
    public static void main(String[] args) throws IllegalAccessException {
//        File file = new File("C:\\Users\\huxingjie\\Documents\\WeChat Files\\huxj0822\\FileStorage\\Temp");
//        //获取该目录下的所有文件
//        String[] files = file.list();
//        System.out.println(files.length);
//        for (String f : files) {
//            System.out.println(f);
//        }
        //listFiles是获取该目录下所有文件和目录的绝对路径
////        File[] fs = file.listFiles();
//        for (File f : fs) {
//            System.out.println(f);
//        }
        Date date = DateUtils.addDays(new Date(), -1);
        System.out.println(date);
        Person p1 = new Person("1", "hxj");
        Person p2 = new Person("1", "hxj2");
        Person p3 = new Person("3", "hxj3");
        List<Person> list = Lists.newArrayList(p1, p3, p2);
        List<Person> people = list.subList(0, 1);
        p1.setId("hxj1111");
        System.out.println(people);
        System.out.println(list);
        List<Person> collect = list.stream().filter(distinctByKey(l -> l.getName())).collect(Collectors.toList());
        System.out.println(collect);
        Person p = new Person("1", "sss");
        Map<String, List<String>> collect1 = list.stream().collect(Collectors.groupingBy(Person::getName, Collectors.mapping(Person::getId, Collectors.toList())));
        System.out.println(collect1);
        List<Integer> l = Lists.newArrayList(new Integer(1), new Integer(2));
        System.out.println(l.contains(1));
        Integer i = new Integer(1);
        Integer j = new Integer(1);
        System.out.println(i.equals(j));
        double totalAmount = 6.6;
        double feeAmount = 1.3;
        BigDecimal tradeAmount = new BigDecimal(String.valueOf(totalAmount))
                .add(new BigDecimal(String.valueOf(feeAmount)));
        System.out.println(tradeAmount);
        Object name = FieldUtils.readField(p3, "name", true);
        System.out.println(name);
        Set<String> set1 = Sets.newHashSet();
        set1.addAll(Lists.newArrayList("1", "2", "3"));
        Set<String> set2 = Sets.newHashSet();
        set2.addAll(Lists.newArrayList( "2","4"));
        SetUtils.SetView<String> intersection = SetUtils.intersection(set1, set2);
        System.out.println("anymous_111".substring("anymous_111".toString().indexOf("_") + 1));
    }

    private static <T> Predicate<T> distinctByKey(Function<? super T, Object> keyExtractor) {
        Set<Object> keyset = Sets.newHashSet();
        return t -> keyset.add(keyExtractor.apply(t));
    }
}

    